/**
 *
 * Copyright by Samuel Castro & Joaquim Fonseca, 2011
 * All Rights Reserved
 *
 * NOTES:
 * Please do not redistribute this plugin without my permission
 * Plugin made for private use only
 *
 */
package com.SySammy.sdRankingSys.Handlers;

import com.SySammy.sdRankingSys.sdRS;
import java.io.File;
import java.util.List;
import org.bukkit.util.config.Configuration;

public class yamlHandler {

    private static final File Ranksfile = new File("plugins/RPGmod/Rank/VocationMaker.yml");
    sdRS plugin;

    public yamlHandler(sdRS plugin) {
        this.plugin = plugin;
    }

    public Configuration load() {
        try {
            Configuration PluginPropConfig = new Configuration(Ranksfile);
            PluginPropConfig.load();
            return PluginPropConfig;

        } catch (Exception e) {
        }
        return null;
    }

    public int NumberOfVocations() {
        Configuration config = load();
        String root = "vocations";
        return config.getKeys(root).size();
    }

    public String NumberOflevels(String Vocation) {
        try {
            Configuration config = load();
            String root = "vocations." + Vocation + "apprentice.level";
            String levels = config.getString(root);
            return levels.split("/")[1];
        } catch (NullPointerException e) {
            return null;
        }
    }

    public String getVocationNames(int x) {
        try {
            Configuration config = load();
            String root = "vocations";
            return (String) config.getKeys(root).toArray()[x];
        } catch (NullPointerException e) {
            return null;
        }
    }

    public List<String> getLevels(String Vocation) {
        Configuration config = load();
        String root = "vocations." + Vocation.toLowerCase();
        return config.getKeys(root);
    }

    public boolean VocationtExists(String vocation) {
        try {
            Configuration config = load();
            String root = "vocations.";
            return config.getKeys(root).contains(vocation.toLowerCase());
        } catch (NullPointerException e) {
            return false;
        }
    }

    public String getlevelCount(String Vocation, String level) {
        try {
            Configuration config = load();
            String root = "vocations." + Vocation.toLowerCase() + "." + level.toLowerCase() + ".level";
            return config.getString(root);
        } catch (NullPointerException e) {
            return null;
        }
    }

    public String getDescription(String Vocation, String level) {
        Configuration config = load();
        String root = "vocations." + Vocation.toLowerCase() + "." + level.toLowerCase() + ".description";
        return config.getString(root);
    }

    public int getExp(String Vocation, String level) {
        Configuration config = load();
        String root = "vocations." + Vocation.toLowerCase() + "." + level.toLowerCase() + ".exp";
        return config.getInt(root, 0);
    }

    public String getColor(String Vocation, String level) {
        Configuration config = load();
        String root = "vocations." + Vocation.toLowerCase() + "." + level.toLowerCase() + ".color";
        return config.getString(root);
    }

    public String getAcronym(String Vocation, String level) {
        Configuration config = load();
        String root = "vocations." + Vocation.toLowerCase() + "." + level.toLowerCase() + ".acronym";
        return config.getString(root);
    }

    public int getPerkQnt(String Vocation, String level) {
        Configuration config = load();
        String root = "vocations." + Vocation.toLowerCase() + "." + level.toLowerCase() + ".perkqnt";
        return config.getInt(root, 0);
    }

    public List<String> getPerks(String Vocation, String level) {
        Configuration config = load();
        String root = "vocations." + Vocation.toLowerCase() + "." + level.toLowerCase() + ".perks";
        return config.getStringList(root, null);
    }

    public List<String> getPermissions(String Vocation, String level) {
        Configuration config = load();
        String root = "vocations." + Vocation.toLowerCase() + "." + level.toLowerCase() + ".permissions";
        return config.getStringList(root, null);
    }
}
